<template>
  <div>
    <van-form @submit="onSubmit">
      <van-field
        v-model.trim="username"
        name="username"
        label="用户名"
        placeholder="请输入用户名"
        :error="false"
        :rules="[
          { required: true, message: '用户名不能为空' },
          { pattern: /^\w{5,}$/, message: '用户名至少包含5个字符' },
        ]"
      />
      <van-field
        v-model.trim="password"
        type="password"
        name="password"
        label="密码"
        placeholder="请输入密码"
        :error="false"
        :rules="[
          { required: true, message: '密码不能为空' },
          { pattern: /^\w{6,}$/, message: '密码至少包含6个字符' },
        ]"
      />
      <div style="margin: 16px">
        <slot name="btn"></slot>
      </div>
    </van-form>
    <div class="link">
      <slot name="link"></slot>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    onSubmit(values) {
      this.$emit("onSubmit", values);
    },
  },
};
</script>

<style lang="less">
.link {
  float: right;
  color: #069;
  font-size: 12px;
  padding-right: 20px;
}
</style>
